﻿using System;
using System.Text;
using Frogism.Core;
using NUnit.Framework;
namespace Frogism.Tests {
  [TestFixture]
  public class UserTest {
    [Test]
    public void EmptyConstructor() {
      User user = new User();
      Assert.IsNotNull(user);
    }
    [Test]
    public void EmailDefaultNull() {
      User user = new User();
      Assert.IsNull(user.Email);
    }
    [Test]
    public void CanSetPassword(){
      User user = new User();
      user.Password = "blah";
      Assert.AreEqual("blah", user.Password);
    }
    [Test]
    public void GetUser()
    {
        var r = new Frogism.Data._2.UserRepository();
        var user = r.GetOne(1);
        Assert.IsNotNull(user);
        Assert.AreEqual("topher", user.Name);
    }
    [Test]
    public void TestHash()
    {
        var mm = new Domain.UserManager();
        var result = mm.HashHexString("oak7fold");

       Assert.AreEqual("300c9451fca7c2f25b8378652e3f380e440a76dbd58bb9af03e3783419e2331d", result);
     
    }
    [Test]
    public void HexTest()
    {
        var expected = "300c9451fca7c2f25b8378652e3f380e440a76dbd58bb9af03e3783419e2331d";
        var encodedbytes = (new UTF8Encoding()).GetBytes(expected);
        string result2 = Convert.ToBase64String(encodedbytes);
        Assert.AreEqual("", result2);
    }
    [Test]
    public void SetTopherPassword()
    {
        var r = (new Data._2.UserRepository());
        var mm = new Domain.UserManager();

        var user = r.GetOne(1);
        var hashedpassword = mm.HashHexString("Diam0nd");
        user.Password = hashedpassword;
        //user.Password = hashedpassword;

        r.Update(user);


        Assert.AreEqual(hashedpassword, r.GetOne(1).Password);
    }
  }
}
